<?php
declare (strict_types = 1);

namespace app\controller;



use app\common\model\Headimgurl;
use app\common\model\Nicknames;
use think\facade\View;

class AdminCreateuser extends AdminInit
{
    public function __construct()
    {

        parent::__construct();
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //共有头像
        $count_headimgurl = Headimgurl::where(1)->count();
        $count_nickname = Nicknames::where(1)->count();
        if(request()->isAjax()){
            $d = request()->param();
            if($d["num"] > 0){
                $end = $d["num"];
            }else{
                $end = 1;
            }

            for ($i=0;$i<= $end;$i++){
                //合成用户
                $h = Headimgurl::order("usetimes ASC")->find();
                $n = Nicknames::order("usetimes ASC")->find();
                $user["headimgurl"] = $h["headimgurl"];
                $user["nickname"] = $n["nickname"];
                $user["username"] = $n["nickname"];
                $user["form"] = '一键合成';
                //p($user);
                $res = \app\common\model\User::create($user);
                if($res){
                    $h->usetimes = $h->usetimes +1;
                    $h->save();
                    $n->usetimes = $n->usetimes +1;
                    $n->save();
                }
            }
            return json(["code"=>200,"msg"=>"成功{$end}个"]);

        }

        View::assign("count_headimgurl",$count_headimgurl);
        View::assign("count_nickname",$count_nickname);
        return  view();
    }


}
